package com.MinesweeperGame.server;

import java.util.Iterator;
import java.util.List;

import javax.jdo.Extent;
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

import com.MinesweeperGame.client.GreetingService;
import com.MinesweeperGame.client.LoginInfo;
import com.MinesweeperGame.client.UserInfo;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;




/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
		GreetingService {
	
	 PersistenceManager pm = LocalPersistanceManager.getPersistenceManager();
	
	@Override
	public String addUser(String uname,String password) throws IllegalArgumentException {
		
		    try {
		      pm.makePersistent(new MinesweeperRegistration(uname, password));
		      pm.flush();
		      System.out.println(""+uname+ password);
		      
		    } finally {
		      pm.close();
		    }
			return password;
			
		  }
	
	public List<LoginInfo> listUsers() {
		
			Extent   extent = pm.getExtent (MinesweeperRegistration.class,true);
	      Iterator    it  = extent.iterator();
	      
	      
	      System.out.print("List of Users");
	      while(it.hasNext())
	      {
	    	  MinesweeperRegistration log = (MinesweeperRegistration) it.next();
	          String user = log.getUserName() ;
	         System.out.println (user);
	      }
		return null;
		  
	  }
		


	public UserInfo getSession() {
		
		return null;
	}

}
